package cn.xinfei.xdecision.engine.runner.service;

import cn.xinfei.xdecision.common.model.enginex.po.Engine;
import cn.xinfei.xdecision.common.model.enginex.po.EngineVersion;
import cn.xinfei.xdecision.engine.runner.executor.NodeHandler;
import cn.xinfei.xdecision.engine.runner.metadata.DecisionFlowLoader;
import cn.xinfei.xdecision.engine.runner.metadata.EngineInfoLoader;
import com.google.common.collect.Table;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Slf4j
@Service
public class ExamNodeService {

    @Autowired
    private DecisionFlowLoader decisionFlowLoader;

    @Autowired
    private EngineInfoLoader engineInfoLoader;


    public Map<String, NodeHandler> getNodeInfo(String engineCode, long versionNo) {
        Table<String, Long, Engine> engineAndVersionMap = engineInfoLoader.getEngineInfo(engineCode,versionNo);
        Map<String, EngineVersion> engineVersionMap = decisionFlowLoader.getEngineVersionInfo(engineAndVersionMap);
        Table<String, String, NodeHandler> nodeHandlerTable = decisionFlowLoader.init(engineVersionMap);
        Map<String, NodeHandler> row = nodeHandlerTable.row(engineCode);
        return row;
    }
}
